package com.itheima.app.controller;

import com.itheima.app.manager.MovementManager;
import com.itheima.domain.mongo.Movement;
import com.itheima.domain.vo.MovementVo;
import com.itheima.domain.vo.PageBeanVo;
import com.itheima.util.ConstantUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Map;

@RestController
public class MovementController {
    @Autowired
    private MovementManager movementManager;

    /**
     * 发布动态
     * @param movement 动态对象
     * @param imageContent 动态图片
     */
    @PostMapping("/movements")
    public void addMovement(Movement movement, MultipartFile[] imageContent) throws IOException {
        movementManager.addMovement(movement, imageContent);
    }

    /**
     * 查询当前用户动态
     * @param page 第几页
     * @param pagesize 每夜显示的条数
     * @param userId 用户id
     * @return 用户的动态信息
     */
    @GetMapping("/movements/all")
    public PageBeanVo findAllMovements(@RequestParam(defaultValue = "1") Integer page,
                                       @RequestParam(defaultValue = "10") Integer pagesize,
                                       Long userId) {
        return movementManager.findAllMovements(page, pagesize, userId);
    }

    /**
     * 查看好友动态
     * @param page 页码
     * @param pagesize 每页条数
     * @return 返回好友动态数据
     */
    @GetMapping("/movements")
    public PageBeanVo FriendMovement(@RequestParam(defaultValue = "1") Integer page,
                                     @RequestParam(defaultValue = "10") Integer pagesize) {
        return movementManager.friendMovement(page,pagesize);
    }

    /**
     * 查看推荐动态列表
     * @param page 页码
     * @param pagesize 每页显示条数
     * @return 推荐动态对象
     */
    @GetMapping("/movements/recommend")
    public PageBeanVo recommendMovement(@RequestParam(defaultValue = "1") Integer page,
                                        @RequestParam(defaultValue = "10") Integer pagesize) {
        return movementManager.recommendMovement(page,pagesize);
    }

    /**
     * 点赞动态
     * @param movementId 动态id
     * @return 点赞数
     */
    @GetMapping("/movements/{movementId}/like")
    public Integer likeMovement(@PathVariable String movementId) {
        return movementManager.likeMovement(movementId);
    }

    /**
     * 取消点赞动态
     * @param movementId 动态id
     * @return 点赞数
     */
    @GetMapping("/movements/{movementId}/dislike")
    public Integer disLikeMovement(@PathVariable String movementId) {
        return movementManager.disLikeMovement(movementId);
    }

    /**
     * 喜欢动态
     * @param movementId 动态id
     * @return 喜欢数
     */
    @GetMapping("/movements/{movementId}/love")
    public Integer loveMovement(@PathVariable String movementId) {
        return movementManager.loveMovement(movementId);
    }

    /**
     * 取消喜欢动态
     * @param movementId
     * @return
     */
    @GetMapping("/movements/{movementId}/unlove")
    public Integer unLoveMovement(@PathVariable String movementId) {
        return movementManager.unLoveMovement(movementId);
    }

    /**
     * 查看单条动态
     * @param movementId 动态id
     * @return 动态vo对象
     */
    @GetMapping("/movements/{movementId}")
    public MovementVo findMovement(@PathVariable String movementId) {
        return movementManager.findMovement(movementId);
    }

    /**
     * 查询评论列表
     * @param movementId 动态id
     * @param page 页码
     * @param pagesize 每页条数
     * @return 评论vo对象
     */
    @GetMapping("/comments")
    public PageBeanVo findCommentList(String movementId,
                                      @RequestParam(defaultValue = "1") Integer page,
                                      @RequestParam(defaultValue = "10") Integer pagesize) {
        return movementManager.findCommentList(movementId, page, pagesize);
    }

    /**
     * 发表评论
     * @param map 动态id和评论
     */
    @PostMapping("/comments")
    public void saveComment(@RequestBody Map<String, String> map) {
        String movementId = map.get("movementId");
        String commentText = map.get("comment");
        movementManager.saveComment(movementId, commentText);
    }

    /**
     * 查询点赞列表
     * @param page 页码
     * @param pagesize 每页条数
     * @return
     */
    @GetMapping("/messages/likes")
    public PageBeanVo messageLike(@RequestParam(defaultValue = "1") Integer page,
                                  @RequestParam(defaultValue = "10") Integer pagesize) {
        return movementManager.message(page, pagesize, ConstantUtil.MOVEMENT_LIKE_1);
    }

    /**
     * 查询喜欢列表
     * @param page 页码
     * @param pagesize 每页条数
     * @return
     */
    @GetMapping("/messages/loves")
    public PageBeanVo messageLove(@RequestParam(defaultValue = "1") Integer page,
                                  @RequestParam(defaultValue = "10") Integer pagesize) {
        return movementManager.message(page, pagesize, ConstantUtil.MOVEMENT_LOVE_3);
    }

    /**
     * 查看点赞列表
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/messages/comments")
    public PageBeanVo messageComment(@RequestParam(defaultValue = "1") Integer page,
                                  @RequestParam(defaultValue = "10") Integer pagesize) {
        return movementManager.message(page, pagesize, ConstantUtil.MOVEMENT_COMMENT_2);
    }


    /**
     * 动态评论点赞
     */
    @GetMapping("/comments/{publishId}/like")
    public Integer likeMovementComment(@PathVariable String publishId ) throws IOException {

        return  movementManager.likeMovementComment( publishId );
    }

    /**
     * 动态评论【取消点赞】
     */
    @GetMapping("/comments/{publishId}/dislike")
    public Integer disLikeMovementComment(@PathVariable String publishId ) throws IOException {

        return  movementManager.disLikeMovementComment( publishId );
    }










}
